using ColorFillGame.Domain.Repositories;
using MediatR;

namespace ColorFillGame.Application.Queries.Player;

public class GetPlayerByConnectionIdQueryHandler : IRequestHandler<ColorFillGame.Application.Queries.Player.GetPlayerByConnectionIdQuery, ColorFillGame.Domain.Entities.Player?>
{
    private readonly IPlayerRepository _playerRepository;

    public GetPlayerByConnectionIdQueryHandler(IPlayerRepository playerRepository)
    {
        _playerRepository = playerRepository;
    }

    public async Task<ColorFillGame.Domain.Entities.Player?> Handle(GetPlayerByConnectionIdQuery request, CancellationToken cancellationToken)
    {
        return await _playerRepository.GetByConnectionIdAsync(request.ConnectionId);
    }
}